package cn.tedu.ivosback.vehicle.controller;

import cn.tedu.ivosback.base.response.JsonResult;
import cn.tedu.ivosback.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivosback.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivosback.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivosback.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆列表:vehicleQuery={}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("selectAll")
    public JsonResult selectAllVehicle() {
        log.debug("查询所有车辆列表");
        List<VehicleVO> list = vehicleService.selectAllVehicle();
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息:vehicleQuery={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("删除车辆信息:id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("/unbind/{id}")
    public JsonResult unbindGeofence(@PathVariable Long id) {
        log.debug("解绑电子围栏:id={}", id);
        vehicleService.unbindGeofence(id);
        return JsonResult.ok();
    }

    @PostMapping("/bind/{vehicleId}/{geoId}")
    public JsonResult bindGeofence(@PathVariable Long vehicleId, @PathVariable Long geoId) {
        log.debug("绑定电子围栏:vehicleId={},geoId={}", vehicleId, geoId);
        vehicleService.bindGeofence(vehicleId, geoId);
        return JsonResult.ok();
    }
}
